package cn.iocoder.yudao.module.picturebook.service.user;


import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.picturebook.controller.admin.user.vo.*;
import cn.iocoder.yudao.module.picturebook.dal.dataobject.user.PBUserDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.picturebook.dal.mysql.user.PBUserMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.picturebook.enums.ErrorCodeConstants.*;

/**
 * 用户信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PBUserServiceImpl implements PBUserService {

    @Resource
    private PBUserMapper pBUserMapper;

    @Override
    public Long createPBUser(PBUserSaveReqVO createReqVO) {
        // 插入
        PBUserDO pBUser = BeanUtils.toBean(createReqVO, PBUserDO.class);
        pBUserMapper.insert(pBUser);

        // 返回
        return pBUser.getId();
    }

    @Override
    public void updatePBUser(PBUserSaveReqVO updateReqVO) {
        // 校验存在
        validatePBUserExists(updateReqVO.getId());
        // 更新
        PBUserDO updateObj = BeanUtils.toBean(updateReqVO, PBUserDO.class);
        pBUserMapper.updateById(updateObj);
    }

    @Override
    public void deletePBUser(Long id) {
        // 校验存在
        validatePBUserExists(id);
        // 删除
        pBUserMapper.deleteById(id);
    }

    @Override
        public void deletePBUserListByIds(List<Long> ids) {
        // 删除
        pBUserMapper.deleteByIds(ids);
        }


    private void validatePBUserExists(Long id) {
        if (pBUserMapper.selectById(id) == null) {
            throw exception(PB_USER_NOT_EXISTS);
        }
    }

    @Override
    public PBUserDO getPBUser(Long id) {
        return pBUserMapper.selectById(id);
    }

    @Override
    public PageResult<PBUserDO> getPBUserPage(PBUserPageReqVO pageReqVO) {
        return pBUserMapper.selectPage(pageReqVO);
    }



}